package com.ct.ecommerce.base.core;

import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;


/**
 *
 *
 * @author changtong
 * @date 2021-50-20
 */
public final class DelayLevelCalculate {

    private DelayLevelCalculate() {
    }

    private static List<Integer> defaultLevel;

    static {
        //RocketMQ 支持的18种等级换算成秒
        defaultLevel = Arrays
            .asList(1, 5, 10, 30, 60, 120, 180, 240, 300, 360, 420, 480, 540, 600, 1200, 1800, 3600,
                7200);
    }

    public static Integer calculateDefault(long second) {
        return IntStream.range(0, 18)
            .filter(i -> defaultLevel.get(i) / (int) second > 0)
            .findFirst().orElse(17);
    }


    public static long get(Integer index) {
        return defaultLevel.get(index);
    }

}